package com.shoppingmall.fragment;

import android.view.View;
import android.widget.CompoundButton;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.zyh.toolslib.base.BaseFragment;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shoppingmall.R;
import com.shoppingmall.activity.mine.MineCollectActivity;
import com.shoppingmall.bean.CollectGoodsBean;
import com.shoppingmall.bean.CollectStoreBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * 2020/3/16
 * 描述：我收藏的店铺
 */
public class MineCollectStoresFragment extends BaseFragment implements MineCollectActivity.OnModifyListener {
    @BindView(R.id.rv_content_list)
    RecyclerView rvContentList;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smartRefresh;

    private boolean modifyState;//是否是编辑状态
    private List<CollectStoreBean> mData = new ArrayList<>();
    private BaseQuickAdapter<CollectStoreBean, BaseViewHolder> mAdapter;
    private List<CollectStoreBean> selectData = new ArrayList<>();

    @Override
    protected int initLayout() {
        return R.layout.fragment_recycleview;
    }

    @Override
    protected void initView(View rootView) {

    }

    @Override
    protected void initData() {
        for (int i = 0; i < 5; i++) {
            mData.add(new CollectStoreBean());
        }
        mAdapter = new BaseQuickAdapter<CollectStoreBean, BaseViewHolder>(R.layout.item_mine_collect_stores, mData) {
            @Override
            protected void convert(@NonNull BaseViewHolder helper, CollectStoreBean item) {
                helper.setGone(R.id.cb_collect, modifyState);
                helper.setOnCheckedChangeListener(R.id.cb_collect, new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        item.setChoosed(b);
                    }
                });
            }
        };
        rvContentList.setLayoutManager(new LinearLayoutManager(mActivity));
        rvContentList.setAdapter(mAdapter);
        ((MineCollectActivity) getActivity()).setOnModifyListener(this);

    }

    @Override
    public void modify(boolean isModifyState) {
        modifyState = isModifyState;
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void cancel() {
        selectData.clear();
        for (int i = 0; i < mData.size(); i++) {
            CollectStoreBean bean = mData.get(i);
            if (bean.isChoosed()) {

                selectData.add(bean);
            }
        }
        ToastUtils.showShort("要删除" + selectData.size() + "个");
    }


}
